package com.chinasofti.zbest.service.impl;

import com.chinasofti.zbest.dao.model.Product;
import com.chinasofti.zbest.dao.model.ShopCart;
import com.chinasofti.zbest.dao.ShopCartMapper;
import com.chinasofti.zbest.service.IShopCartService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinasofti.zbest.service.info.ProductCartInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 购物车 服务实现类
 * </p>
 *
 * @author zbest
 * @since 2019-05-28
 */
@Service
@Slf4j
public class ShopCartServiceImpl extends ServiceImpl<ShopCartMapper, ShopCart> implements IShopCartService {

    @Autowired
    private ShopCartMapper shopCartMapper;

    @Override
    public List<ShopCart> query(int userId) {
        return shopCartMapper.queryByUserId(userId);
    }



    @Override
    public Product queryByProNum(String proNum) {
        return shopCartMapper.queryByProNum(proNum);
    }

    @Override
    public void addProduct(ShopCart shopCart) {

        shopCartMapper.addToCart(shopCart);

    }
    @Override
    public void del(Integer userId, String productNumber) {
        shopCartMapper.delBy(userId,productNumber);
    }

    @Override
    public ShopCart queryForReduce(String productNumber) {
        return shopCartMapper.queryForModify(productNumber);
    }

    @Override
    public void reduceCountByProductNumber(String productNumber, Integer productCount,Double countPrice) {
        log.info("ServiceImpl"+"数量"+productCount+"总价"+countPrice);
        shopCartMapper.reduceProductCount(productNumber,productCount,countPrice);
    }


    @Override
    public ShopCart queryByCartId(Integer shopCartId) {
        ShopCart shopCart = shopCartMapper.queryByShopCartId(shopCartId);
        return shopCart;
    }
}
